package com.emptyMe.product.controller;

import com.emptyMe.basic.utils.AjaxResult;
import com.emptyMe.org.domain.Department;
import com.emptyMe.product.domain.Product;
import com.emptyMe.product.query.ProductQuery;
import com.emptyMe.product.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product")
@Api(tags = "产品接口",description = "产品详细api描述")
public class ProductController {
    @Autowired
    private IProductService service;

    @PostMapping
    @ApiOperation(value = "分页查询")
    public AjaxResult loadAll(@RequestBody ProductQuery query){
        return service.loadAll(query);
    }

    @PutMapping
    @ApiOperation(value = "修改操作")
    public AjaxResult update(@RequestBody Product product){
        return service.addOrUpdate(product);
    }


    @DeleteMapping("/{id}")  // product/2
    @ApiOperation(value = "产品删除",notes = "删除该id下的产品")
    public AjaxResult delete(@PathVariable("id") Long id) {
        return service.remove(id);
    }


    @DeleteMapping("/delMany")  // product/2
    @ApiOperation(value = "产品批量删除",notes = "批量删除产品服务")
    public AjaxResult deleteMany(@RequestBody List<Product> products) {
        return service.removeMany(products);
    }

}
